package com.example.apple.ddhr_new;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.widget.ImageView;


import com.bumptech.glide.Glide;
import com.example.apple.ddhr_new.utils.BaiDuUtil;
import com.previewlibrary.ZoomMediaLoader;
import com.previewlibrary.loader.IZoomMediaLoader;
import com.previewlibrary.loader.MySimpleTarget;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import utils.DebugUtil;

public class App extends Application {



    public BaiDuUtil baiDuUtil;
    private static final String DATA_BASE_NAME ="DDHR" ;
    private static App INSTANCE;
//    private static DaoSession mDaoSession;

    public static App self() {
        return INSTANCE;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        INSTANCE = this;
        baiDuUtil =new BaiDuUtil(this);
        ZXingLibrary.initDisplayOpinion(this);
        ZoomMediaLoader.getInstance().init(new IZoomMediaLoader() {
            @Override
            public void displayImage(@NonNull Fragment fragment, @NonNull String s, ImageView imageView, @NonNull MySimpleTarget mySimpleTarget) {
                Glide.with(fragment).load(s).into(imageView);
            }

            @Override
            public void displayGifImage(@NonNull Fragment fragment, @NonNull String s, ImageView imageView, @NonNull MySimpleTarget mySimpleTarget) {
                Glide.with(fragment).load(s).into(imageView);
            }

            @Override
            public void onStop(@NonNull Fragment fragment) {
                Glide.with(fragment).onStop();
            }

            @Override
            public void clearMemory(@NonNull Context c) {
                Glide.get(c).clearMemory();
            }

        });

        initCloudChannel(this);
//        CrashHandler crashHandler = CrashHandler.getInstance();
//        crashHandler.init(this);
        initDataBase();
    }
    private void initDataBase(){
//        DaoMaster.DevOpenHelper helper = new  DaoMaster.DevOpenHelper(this,DATA_BASE_NAME);
//        Database db = helper.getWritableDb();
//        DaoMaster daoMaster = new DaoMaster(db);
//        mDaoSession = daoMaster.newSession();
    }
//
//    @Override
//    public void onTerminate() {
//        super.onTerminate();
//    }
//
//    public  static  DaoSession getmDaoSession(){
//        return  mDaoSession;
//    }
    /**
     * 初始化云推送通道
     * @param applicationContext
     */
    private void initCloudChannel(final Context applicationContext) {
        this.createNotificationChannel();
    }
    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);



            // 通知渠道的id
            String id = "1";
            // 用户可以看到的通知渠道的名字.
            CharSequence name = "点点人事推送";
            // 用户可以看到的通知渠道的描述
            String description = "notification description";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(id, name, importance);
            // 配置通知渠道的属性
            mChannel.setDescription(description);
            // 设置通知出现时的闪灯（如果 android 设备支持的话）
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            // 设置通知出现时的震动（如果 android 设备支持的话）
            mChannel.enableVibration(true);
//            mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
//            mChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
            //最后在notificationmanager中创建该通知渠道
            mNotificationManager.createNotificationChannel(mChannel);




        }
    }


}
